// 引入express
const express = require("express");
const history = require("connect-history-api-fallback");
const { createProxyMiddleware } = require('http-proxy-middleware');
// 配置端口号
const PORT = 8088;

// 创建一个app服务实例
const app = express();

app.use(history());

// 配置静态资源
app.use(express.static(__dirname + "/public"));

app.use(
  '/api',
  createProxyMiddleware({
    target: 'http://sph-api.atguigu.cn',
    changeOrigin: true,
		pathRewrite: {
			'^/api': ''
		}
  }),
);

/* app.get("*", (req, res) => {
  res.sendFile(__dirname + "/public/index.html");
});
 */
// 绑定端口监听
app.listen(PORT, () => {
  console.log(`本地服务器启动成功，http://localhost:${PORT}`);
});
